class BootStrap {

     def init = { servletContext ->
         def r1 = new Grole(name:"default").save();
         
println "r1=" + r1        
        
	def pr1 = new Gprofile(
		displayName:"user1",location:"detroit",imageName:"none",
                homepageUri:"http://facebook.com", address:"15814 amore",
                city:"clinton twp", state:"MI", country:"usa", postcode: "27596",
                phoneNumber:"919-455-8488"
		).save()
                
println "pr1=" + pr1

	def pr2 = new Gprofile(
		displayName:"admin1",location:"raleigh",imageName:"none",
                homepageUri:"http://my.yahoo.com", address:"8172 thornhill",
                city:"clinton twp", state:"MI", country:"usa", postcode: "15814",
                phoneNumber:"919-562-8841"
		).save()
println "pr2=" + pr2

         def u = new Guser(
                name:"user",
                password:"pass",
                activationCode:"123",
	        activationDate:new Date(),
	        profile:pr1,
                email:"user@nowhere.com"
        ).save();

println "u=" + u
        u.addToRoles(r1);
        u.save(flush:true);
        
        def u2 = new Guser(
                name:"admin",
                password:"admin",
                activationCode:"123",
	        activationDate:new Date(),
	        profile:pr2,
                email:"user@nowhere.com").save();
        def r2 = new Grole(name:"admin").save();
        u2.addToRoles(r2);
        // have to flush to save the relationship data
        u2.save(flush:true);
        
        def p1 = new Gpermission(name:"edit").save();
        def p2 = new Gpermission(name:"delete").save();
        def p3 = new Gpermission(name:"read").save();
        r2.addToPermissions(p1)
        r2.addToPermissions(p2)
        r2.addToPermissions(p3)
        r1.addToPermissions(p3)
        r1.save(flush:true)
        r2.save(flush:true)


	def n = new News(status:"published",article:"This is the article",title:"Sample news 1",caption:"Sample1").save()
	n.addToRoles(r1)
	r1.save(flush:true)
	n.save(flush:true)


     }
     def destroy = {
     }
} 
